﻿using System;
using System.Data;
using MedicService.Domain.Print.Template;
using MedicService.Server.Factory.Generic;

namespace MedicService.Server.Factory.Print {
    public class PrintTemplateInvoiceFactory : DirectorySimpleFactory<PrintTemplateInvoice> {
        public PrintTemplateInvoiceFactory() : base("PrintTemplateInvoice") { }
        protected override PrintTemplateInvoice CreateEntity() {
            return new PrintTemplateInvoice();
        }

        protected override string GetInsertQuery(PrintTemplateInvoice entity) {
            string q = "INSERT INTO [PrintTemplateInvoice]"
                       + "           ([_accepter]"
                       + "           ,[title]"
                       + "           ,[_bik]"
                       + "           ,[_bank]"
                       + "           ,[_inn]"
                       + "           ,[_kpp]"
                       + "           ,[_sp]"
                       + "           ,[_ksch]"
                       + "           ,[_ls]"
                       + "           ,[_summ]"
                       + "           ,[_vid])"
                       + "     VALUES"
                       + "           (" + Nullable(entity._accepter)
                       + "           ," + Nullable(entity.Title)
                       + "           ," + Nullable(entity._bik)
                       + "           ," + Nullable(entity._bank)
                       + "           ," + Nullable(entity._inn)
                       + "           ," + Nullable(entity._kpp)
                       + "           ," + Nullable(entity._sp)
                       + "           ," + Nullable(entity._ksch)
                       + "           ," + Nullable(entity._ls)
                       + "           ," + Nullable(entity._summ)
                       + "           ," + Nullable(entity._vid) + ")";
            return q;
        }

        protected override string GetUpdateQuery(PrintTemplateInvoice entity) {
            string q = "UPDATE [PrintTemplateInvoice]"
                       + "   SET [_accepter] = " + Nullable(entity._accepter)
                       + "      ,[title] = " + Nullable(entity.Title)
                       + "      ,[_bik] = " + Nullable(entity._bik)
                       + "      ,[_bank] = " + Nullable(entity._bank)
                       + "      ,[_inn] = " + Nullable(entity._inn)
                       + "      ,[_kpp] = " + Nullable(entity._kpp)
                       + "      ,[_sp] = " + Nullable(entity._sp)
                       + "      ,[_ksch] = " + Nullable(entity._ksch)
                       + "      ,[_ls] = " + Nullable(entity._ls)
                       + "      ,[_summ] = " + Nullable(entity._summ)
                       + "      ,[_vid] = " + Nullable(entity._vid)
                       + " WHERE id=" + entity.Id;
            return q;
        }

        protected override void FillEntity(PrintTemplateInvoice entity, DataRow myDataRow) {
            base.FillEntity(entity, myDataRow);
            entity._accepter = myDataRow["_accepter"] as string;
            entity._bik = myDataRow["_bik"] as string;
            entity._bank = myDataRow["_bank"] as string;
            entity._inn = myDataRow["_inn"] as string;
            entity._kpp = myDataRow["_kpp"] as string;
            entity._sp = myDataRow["_sp"] as string;
            entity._ksch = myDataRow["_ksch"] as string;
            entity._ls = myDataRow["_ls"] as string;
            entity._summ = myDataRow["_summ"] as string;
            entity._vid = myDataRow["_vid"] as string;
        }

    }
}